package com.haiyou.data.common.persister.mysql.help.invoke;

import com.haiyou.common.entity.Entity;
import com.haiyou.data.common.persister.mysql.help.ColumnHelper;
import com.haiyou.data.common.persister.mysql.meta.ColumnMeta;

public class TextHelper implements InvokeHelper {

	@Override
	public void invoke(ColumnMeta columnMeta, Object ov, Entity<?> entity) {
		try {
			ColumnHelper.getSetter(columnMeta).invoke(entity, ov.toString());// 尝试直接使用string赋值
		} catch (Exception e) {
			try {
				Object value = com.alibaba.fastjson2.JSON.parseObject(ov.toString(),
						ColumnHelper.getGenericType(columnMeta));// 使用fastjson反序列化后赋值
				ColumnHelper.getSetter(columnMeta).invoke(entity, value);
			} catch (Exception ex) {
				throw new RuntimeException(e.getMessage() + ":" + ov + ",\n" + entity + ",\n" + columnMeta, e);
			}
		}
	}

}
